<?php
/* @var $this AlunoController */
/* @var $model Aluno */
/* @var $form CActiveForm */
?>
<script>
  $(function() {
	  var MyCheckboxes=$("input[name='checkresponsavel']");

	  MyCheckboxes.change(function() {
	    $("#responsavel_div1").toggle(MyCheckboxes.is(":checked"));
	    $("#responsavel_div2").toggle(MyCheckboxes.is(":checked"));
	    $("#responsavel_div3").toggle(MyCheckboxes.is(":checked"));
	  });
  });
  </script>

<div class="form">
	<?php
	$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
			'id' => 'aluno-form',
			'enableAjaxValidation' => false,
			'enableClientValidation' => true,
			'htmlOptions' => array('enctype' => 'multipart/form-data'),
	));
	?>

	<p class="note">
		Campos com <span class="required">*</span> são obrigatórios.
	</p>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'foto'); ?>
			<?php if($model->isNewRecord!='1'){ ?> <?php echo CHtml::image(Utils::findImageUrl($model->foto), $pessoa->nome,array('width'=>'100px', 'border' =>'1px solid #dddddd')); ?>

			<?php }?> <?php echo CHtml::activeFileField($model, 'foto'); ?> <?php echo $form->error($model, 'foto'); ?>
		</span>

	</div>

	<div class="row">
		<span style="float: left; width: 500px;"> <?php echo $form->labelEx($pessoa, 'nome'); ?>
			<?php echo $form->textField($pessoa,'nome',array('class'=>'span5','maxlength'=>250)); ?>
			<?php echo $form->error($pessoa, 'nome'); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($pessoa, 'cpf'); ?>
			<?php
			$this->widget('CMaskedTextField', array(
					'model' => $pessoa,
					'attribute' => 'cpf',
					'name' => 'cpf_field',
					'mask' => '99999999999',
					'htmlOptions' => array(
							'style' => 'width:207px;'
					),
			));
			?> <?php echo $form->error($pessoa, 'cpf'); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($pessoa, 'data_de_nascimento'); ?>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
					'model' => $pessoa,
					'attribute' => 'data_de_nascimento',
					'name' => 'data_de_nascimento',
					'options'=>array(
							'type' => 'date',
							'dateFormat'=>'dd-mm-yy',
							'style' => 'width:100px',
							'showAnim'=>'slide',//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
							'changeMonth'=>true,
							'changeYear'=>true,
							'yearRange'=>'1900:2099',
							'minDate' => '01-01-1900',      // minimum date
							'maxDate' => '31-12-2099',
					),
			));
			?> <?php echo $form->error($pessoa, 'data_de_nascimento'); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($pessoa, 'genero'); ?>
			<?php echo $form->dropDownList($pessoa, 'genero', array('Masculino' => 'Masculino', 'Feminino' => 'Feminino'), array('empty' => '')); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($pessoa, 'rg'); ?>
			<?php echo $form->textField($pessoa, 'rg', array('maxlength' => 10)); ?>
			<?php echo $form->error($pessoa, 'rg'); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 500px;"> <?php echo $form->labelEx($pessoa, 'endereco'); ?>
			<?php echo $form->textField($pessoa, 'endereco', array('class'=>'span5', 'maxlength' => 250)); ?>
			<?php echo $form->error($pessoa, 'endereco'); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($pessoa, 'naturalidade'); ?>
			<?php echo $form->textField($pessoa, 'naturalidade', array('maxlength' => 45)); ?>
			<?php echo $form->error($pessoa, 'naturalidade'); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 500px;"> <?php echo $form->labelEx($pessoa, 'email'); ?>
			<?php echo $form->textField($pessoa,'email',array('class'=>'span5','maxlength'=>250)); ?>
			<?php echo $form->error($pessoa, 'email'); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($pessoa, 'cep'); ?>
			<?php
			$this->widget('CMaskedTextField', array(
					'model' => $pessoa,
					'attribute' => 'cep',
					'name' => 'cep',
					'mask' => '99999999',
					'htmlOptions' => array(
							'style' => 'width:207px;'
					),
			));
			?> <?php echo $form->error($pessoa, 'cep'); ?>
		</span>

	</div>
	<div class="row">
		<span style="float: left; width: 500px;"> <?php echo $form->labelEx($model, 'bairro'); ?>
			<?php echo $form->textField($model,'bairro',array('class'=>'span5','maxlength'=>250)); ?>
			<?php echo $form->error($model, 'bairro'); ?>
		</span><span style="float: left; width: 150px;"> <?php echo $form->labelEx($model, 'zona'); ?>
			<?php echo $form->dropDownList($model, 'zona', Aluno::$zonas, array('empty' => '')); ?>
		</span>
	</div>

	<div class="row">
		<span style="float: left; width: 500px;"> <?php echo $form->labelEx($model, 'ponto_referencia'); ?>
			<?php echo $form->textField($model, 'ponto_referencia', array('class'=>'span5', 'maxlength' => 250)); ?>
			<?php echo $form->error($model, 'ponto_referencia'); ?>
		</span><span style="float: left; width: 150px;"> <?php echo $form->labelEx($pessoa, 'uf'); ?>
			<?php echo $form->textField($pessoa, 'uf', array('size' => 26, 'maxlength' => 45)); ?>
			<?php echo $form->error($pessoa, 'uf'); ?>
		</span>

	</div>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($pessoa, 'telefone'); ?>
			<?php echo $form->textField($pessoa, 'telefone', array('maxlength' => 20)); ?>
			<?php echo $form->error($pessoa, 'telefone'); ?>
		</span> <span style="float: left; width: 400px;"> <?php echo $form->labelEx($model, 'falar_tele'); ?>
			<?php echo $form->textField($model, 'falar_tele', array('class'=>'span5','maxlength' => 20)); ?>
			<?php echo $form->error($model, 'falar_tele'); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($pessoa, 'celular'); ?>
			<?php echo $form->textField($pessoa, 'celular', array('maxlength' => 20)); ?>
			<?php echo $form->error($pessoa, 'celular'); ?>
		</span> <span style="float: left; width: 400px;"> <?php echo $form->labelEx($model, 'falar_cel'); ?>
			<?php echo $form->textField($model, 'falar_cel', array('class'=>'span5','maxlength' => 20)); ?>
			<?php echo $form->error($model, 'falar_cel'); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'renda_familiar'); ?>
			<?php echo $form->dropDownList($model, 'renda_familiar', Aluno::$renda_familiar, array('empty' => '')); ?>
			<?php echo $form->error($model, 'renda_familiar'); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'situacao_escolar'); ?>
			<?php echo $form->dropDownList($model, 'situacao_escolar', Aluno::$situacoes_escolares, array('empty' => '')); ?>
		</span><span style="float: left; width: 150px;"> <?php echo $form->labelEx($pessoa, 'escolaridade'); ?>
			<?php echo $form->dropDownList($pessoa, 'escolaridade', Pessoa::$escolaridades, array('empty' => '')); ?>
		</span>


	</div>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'zona_escola'); ?>
			<?php echo $form->textField($model, 'zona_escola', array('size' => 50, 'maxlength' => 45)); ?>
			<?php echo $form->error($model, 'zona_escola'); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'nome_escola'); ?>
			<?php echo $form->textField($model, 'nome_escola', array('size' => 50, 'maxlength' => 250)); ?>
			<?php echo $form->error($model, 'nome_escola'); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($pessoa, 'rede_ensino'); ?>
			<?php echo $form->dropDownList($pessoa, 'rede_ensino', Pessoa::$redes_ensino, array('empty' => '')); ?>
		</span>
	</div>

	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'profissao'); ?>
			<?php echo $form->dropDownList($model, 'profissao', Aluno::$profissoes, array('empty' => '')); ?>
			<?php echo $form->error($model, 'telefone_pai'); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'estado_civil'); ?>
			<?php echo $form->dropDownList($model, 'estado_civil', Aluno::$estados_civis, array('empty' => '')); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($model, 'inicio_deficiencia'); ?>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
					'model' => $model,
					'attribute' => 'inicio_deficiencia',
					'name' => 'inicio_deficiencia',
					'htmlOptions' => array(
							'type' => 'date',
							'dateFormat'=>'dd-mm-yy',
							'style' => 'width:207px',
							'showAnim'=>'slide',
							'changeMonth'=>true,
							'changeYear'=>true,
							'yearRange'=>'1900:2099',
							'minDate' => '01-01-1900',      // minimum date
							'maxDate' => '31-12-2099',
					),
			));
			?> <?php echo $form->error($model, 'inicio_deficiencia'); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'certidao_numero'); ?>
			<?php echo $form->textField($model, 'certidao_numero', array('size' => 22, 'maxlength' => 45)); ?>
			<?php echo $form->error($model, 'certidao_numero'); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'certidao_folha'); ?>
			<?php echo $form->textField($model, 'certidao_folha', array('size' => 22, 'maxlength' => 45)); ?>
			<?php echo $form->error($model, 'certidao_folha'); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($model, 'certidao_livro'); ?>
			<?php echo $form->textField($model, 'certidao_livro', array('size' => 21, 'maxlength' => 45)); ?>
			<?php echo $form->error($model, 'certidao_livro'); ?>
		</span>
	</div>

	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'certidao_cartorio'); ?>
			<?php echo $form->textField($model, 'certidao_cartorio', array('size' => 21, 'maxlength' => 45)); ?>
			<?php echo $form->error($model, 'certidao_cartorio'); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'tipo_sanguineo'); ?>
			<?php echo $form->dropDownList($model, 'tipo_sanguineo', Aluno::$tipos_sanguineos, array('empty' => '')); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($model, 'tipo_habitacao'); ?>
			<?php echo $form->dropDownList($model, 'tipo_habitacao', Aluno::$tipos_habitacao, array('empty' => '')); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'ocupacao_imovel'); ?>
			<?php echo $form->dropDownList($model, 'ocupacao_imovel', Aluno::$ocupacoes_imovel, array('empty' => '')); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'eletrica'); ?>
			<?php echo $form->dropDownList($model, 'eletrica', Aluno::$instalacoes_eletricas, array('empty' => '')); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($model, 'hidraulica'); ?>
			<?php echo $form->dropDownList($model, 'hidraulica', Aluno::$instalacoes_hidraulicas, array('empty' => '')); ?>
		</span>
	</div>

	<div class="row">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($model, 'observacao'); ?>
			<?php echo $form->textField($model,'observacao',array('class'=>'span5','maxlength'=>250)); ?>
		</span>
	</div>
	<div class="row">
		<span style="float: left; width: 500px;"> <?php 
		$funcionarios = Funcionario::model()->findAllByAttributes(array('polo_id' => Yii::app()->session['polo_id']));
		$data = array();
		foreach ($funcionarios as $funcionario) {
			$pessoa = Pessoa::model()->findByAttributes(array('id'=>$funcionario->pessoa_id));
			if($funcionario->id != 1) {
				$data[$funcionario->id] = $pessoa->nome;
			}
		} ?> <?php echo $form->labelEx($model,'atendente_id'); ?> <?php echo $form->dropDownList($model, 'atendente_id', $data, array('class'=>'span5','empty' => '')); ?>
			<?php echo $form->error($model, 'atendente_id'); ?>
		</span>
	</div>

	<?php $has_responsavel = $model->responsavel_id != 0;?>


	<br /> <br />
	<legend>
		<h4 align="center">Responsável</h4>
	</legend>
	<div class="row">
		<br /> <span style="float: left; width: 400px;"> <?php echo $form->checkBox($model, 'responsavel_id', array(
				'name' => 'checkresponsavel',
				'value' => '1',
				'checked' => $model->responsavel_id == 0 ? '0' : '1',
				'uncheckValue' => null,
				)) . ' Possui Responsavel   ';?>

		</span>
	</div>
	<br />
	<div id="responsavel_div1" class="row" style="display: <?php if($has_responsavel) { echo "visible"; } else { echo "none"; }?>">
		<span style="float: left; width: 500px;"> <?php echo $form->labelEx($responsavel, 'nome'); ?>
			<?php echo $form->textField($responsavel,'nome',array('class'=>'span5','maxlength'=>250)); ?>
			<?php echo $form->error($responsavel, 'nome'); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($responsavel, 'sexo'); ?>
			<?php echo $form->dropDownList($responsavel, 'sexo', array('Masculino' => 'Masculino', 'Feminino' => 'Feminino'), array('empty' => '')); ?>
			<?php echo $form->error($responsavel, 'sexo'); ?>
		</span>
	</div>
	<div id="responsavel_div2" class="row" style="display: <?php if($has_responsavel) { echo "visible"; } else { echo "none"; }?>">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($responsavel, 'cpf'); ?>
			<?php
			$this->widget('CMaskedTextField', array(
					'model' => $responsavel,
					'attribute' => 'cpf',
					'mask' => '99999999999',
					'htmlOptions' => array(
							'style' => 'width:207px;'
					),
			));
			?> <?php echo $form->error($responsavel, 'cpf'); ?>

		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($responsavel, 'data_de_nascimento'); ?>
			<?php
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
					'model' => $responsavel,
					'attribute' => 'data_de_nascimento',
					'name' => 'nascimento_responsavel',
					'options'=>array(
							'type' => 'date',
							'dateFormat'=>'dd-mm-yy',
							'style' => 'width:100px',
							'showAnim'=>'slide',//'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
							'changeMonth'=>true,
							'changeYear'=>true,
							'yearRange'=>'1900:2099',
							'minDate' => '01-01-1900',      // minimum date
							'maxDate' => '31-12-2099',
					),
			));
			?> <?php echo $form->error($responsavel, 'data_de_nascimento'); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($responsavel, 'rg'); ?>
			<?php echo $form->textField($responsavel, 'rg', array('maxlength' => 10)); ?>
			<?php echo $form->error($responsavel, 'rg'); ?>
		</span>
	</div>
	<div id="responsavel_div3" class="row" style="display: <?php if($has_responsavel) { echo "visible"; } else { echo "none"; }?>">
		<span style="float: left; width: 250px;"> <?php echo $form->labelEx($responsavel, 'estado_civil'); ?>
			<?php echo $form->dropDownList($responsavel, 'estado_civil', Aluno::$estados_civis, array('empty' => '')); ?>
			<?php echo $form->error($responsavel, 'estado_civil'); ?>
		</span> <span style="float: left; width: 250px;"> <?php echo $form->labelEx($responsavel, 'profissao'); ?>
			<?php echo $form->dropDownList($responsavel, 'profissao', Aluno::$profissoes, array('empty' => '')); ?>
		</span> <span style="float: left; width: 150px;"> <?php echo $form->labelEx($responsavel, 'telefone'); ?>
			<?php echo $form->textField($responsavel, 'telefone', array('maxlength' => 20)); ?>
			<?php echo $form->error($responsavel, 'telefone'); ?>
		</span>
	</div>
	<br /> <br />

	<?php
	$caracteristicas = Caracteristica::model()->findAll();
	$myCaracteristics = array();
	$relations = array();

	echo '<legend><h4 align="center" >Características</h4></legend><br/>';
	foreach (Caracteristica::$tipos as $tipo) {
		?>
	<span style="float: left; width: 142px;"> <?php
	echo "<h5>$tipo</h5>";
	foreach ($caracteristicas as $caract) {
		if ($caract->tipo == $tipo) {
			echo '<div class="row" style="background: #FFFFFF">';
			echo $form->checkBox($caracteristica, 'nome', array(//TODO: codigo deve ser alterado.
					'name' => 'check' . $caract->id,
					'value' => $caract->nome,
					'checked' => in_array($caract->nome, $info) ? '1' : '0',
					'uncheckValue' => null)) . ' ';
			echo $caract->nome;
			echo '</div>';
		}
	}
	?>
	</span>
	<?php
	}
	?>



	<div class="row">
		<?php
		echo '<br/><legend><h4  align="center">Triagem</h4></legend><br/>';
		echo '<Table BORDER="0">';
		echo "<TR><TD>Nome</TD><TD> SIM</TD><TD>NÃO</TD><TD>Observação</TD></TR>";
		foreach (Aluno::$triagem as $key => $value) {
			echo '<TR>';
			echo "<TD>$value</TD>";
			echo "<TD><h6>";
			echo $form->radioButton($caracteristica, 'nome', array(
					'name' => 'check' . $key,
					'value' => 'Sim',
					'checked' => in_array($key, $info) ? '1' : '0',
					'uncheckValue' => null)) . ' ';
			echo '</h6></TD>';
			echo "<TD>";
			echo $form->radioButton($caracteristica, 'nome', array(
					'name' => 'check' . $key,
					'value' => 'NÃ£o',
					'checked' => in_array($key, $info) ? '0' : '1',
					'uncheckValue' => null)) . ' ';
			echo '</TD>';
			echo "<TD>";
			$text = "";
			if(array_key_exists($key, $obs)) {
				$text = $obs[$key];
			}
			echo $form->textField($caracteristica, 'nome', array('name' => 'obs' . $key, 'value' =>$text ,'size' => 50, 'maxlength' => 250));
			echo '</TD>';
			echo '</TR>';
		}
		echo '</Table>';
		?>
	</div>

	<br /> <br />
	<div align="center" class="form-actions">

		<?php $this->widget('bootstrap.widgets.TbButton', array(
				'buttonType'=>'submit',
				'type'=>'primary',
				'label' => $model->isNewRecord ? '    Cadastrar    ' : '    Salvar     ',
				'htmlOptions' => array('class' => 'ui-button-primary')
		));
		?>
	</div>


	<?php $this->endWidget(); ?>

</div>
<!-- form -->
